{include file="head.html"}
<style>
.table_style td { border-bottom:1px #ddd solid;}
.libel_list {background-color:#f5f5f5; border:1px #ccc solid;  padding:5px;}
.libel_list a { padding-left:10px; float:left; padding-right:10px; line-height:22px; height:22px; background-color:#fefefe; border:1px #ddd solid; margin-top:3px;margin-right:10px;}
.title_width { width:120px; line-height:25px; float:left;}
.listcontent { width:300px; float:left;}
#echo { line-height:20px; font-size:12px;}
</style>
<script src="__PUBLIC__/js/insertContent.js"></script>
<div id="maincontent">
  <div class="wrap">
    <div class="tip"> {lang='添加标签后会自动生成相应标签，把标签放入模板需要位置即可。'}  </div>
    <form action="__URL__/edit" id="form" method="post">
      <div class="infobox">
        <h3>{lang='其他标签编辑'}</h3>
        <table class="form-table table_style">
          <tr>
            <td><strong>{lang='标签信息'}：</strong></td>
          </tr>
          <tr>
            <td><div class="title_width">{lang='标签名称'}：</div>
              <input name="name" type="text" class="regular-text" id="name" value="{$info['name']}" /></td>
          </tr>
          <tr>
            <td><div class="title_width">{lang='标签标识'}：</div>
              <input name="label" type="text" class="regular-text" id="label" value="{$info['label']}" /></td>
          </tr>
          <tr>
            <td><strong>{lang='调用参数'}：</strong></td>
          </tr>
          <tr>
            <td>
                <input name="table" type="text" class="regular-text" id="table" style="width:120px;" value="{$config['table']}" />
                <select style="width:130px;" onChange="$('#table').val(decodeURIComponent($(this).val()));getfields($(this).val())"  >
                  <option value="" selected="selected">{lang='选择表'}</option>
                  <?php if(!empty($tables)) foreach($tables as $vo){ ?>
                  <option value="{$vo}">{$vo}</option>
                  <?php } ?>
                </select>
              <input name="limit" type="text" class="regular-text" id="limit" style="width:100px;" value="{$config['limit']}" />
              {lang='条'} </td>
          </tr>
          <tr>
            <td>
              <input name="order" type="text" class="regular-text" id="order" style="width:200px;" value="{$config['order']}" />
              <select onChange="$('#order').val($(this).val())">
                <option value="id desc" selected="selected">{lang='按ID倒序排序'}</option>
                <option value="id asc">{lang='内容按ID升序排序'}</option>
              </select></td>
          </tr>
          <tr>
            <td><strong>{lang='附加SQL条件'}：</strong>({lang='说明:附件条件为标准的SQL和PHP语法。'})</td>
          </tr>
          <tr>
            <td>
              <input name="where" type="text" class="regular-text" id="where" value="{$config['where']}" />
              <select onChange="$('#where').val($(this).val())">
                <option value="">{lang='无'}</option>
                <option value="pid=1">{lang='查询pid为1的列表(示例)'}</option>
              </select>
             </td>
          </tr>
          <tr>
            <td><strong>{lang='循环标识'}：</strong>({lang='如果为多维循环循环标识不能相同，多维循环请点击"插入循环标签"插入在外部循环内。'})</td>
          </tr>
          <tr>
            <td>
                <input name="mark" type="text" class="regular-text" id="mark" style="width:100px;" value="{$config['mark']}" />
               </td>
          </tr>
          
          <tr>
            <td><button type="button" onclick="out_label()">{lang='输出标签'}</button>
              <button type="button" onclick="out_taglabel()">{lang='TAG循环标签'}</button>
              <button type="button" onclick="out_navlabel()">{lang='位置导航标签'}</button></td>
          </tr>
          <tr>
            <td> {lang='以下为生成的标签代码，请自行选取使用。'}</td>
          </tr>
          <tr>
            <td><div class="libel_list">
                <div style="clear:both"></div>
                <div id="label_list"> <a href="javascript:void(0)"  onclick="ins_html()">{lang='请先选择表'}</a> </div>
                <div style="clear:both"></div>
              </div>
              <textarea name="content" id="echo" style="width:99%; height:150px; border:1px solid #ccc; margin-top:10px;"><?php echo html_out($info['content']) ?></textarea>
              <div>{lang='点击上面各个标签按钮会插入相应的标签代码，请将代码插入循环内部。'}</div></td>
          </tr>
        </table>
      </div>
      <div class="submit_body">
        <input name="type" id="type" type="hidden" value="3" />
        <input name="id" id="id" type="hidden" value="{$info['id']}" />
        <button class="regular-button" type="button" onclick="post()">{lang='编辑'}</button>
      </div>
    </form>
  </div>
</div>
<script>
function out_label() {
	
	var table=$('#table').val(); //表名
	
	var limit=' limit=('+$('#limit').val()+')'; //调用条数
	
	var order=' order=('+$('#order').val()+')'; //排序类型
	
	var mark=$('#mark').val(); //循环标识
	
	if($('#where').val()==""){
		var where='';
	}else{
		var where=' where=('+$('#where').val()+')'; //附加条件
	}
	
	
	var outhtml="<!--"+mark+":{table=("+table+")";
	outhtml+=limit;
	outhtml+=order;
	outhtml+=where;
	outhtml+="}-->\n";
	outhtml+='循环内调用\n';
	outhtml+="<!--/"+mark+"-->";
	
	$('#echo').attr("value",outhtml);

};



function out_taglabel() {
	
	
	var limit=' limit=('+$('#limit').val()+')'; //调用条数
	
	var order=' order=('+$('#order').val()+')'; //排序类型
	
	var mark=$('#mark').val(); //循环标识
	
	
	var outhtml="<!--"+mark+":{table=(content_tag)";
	outhtml+=limit;
	outhtml+=order;
	outhtml+=" }-->\n";
	outhtml+='<a href="__'+'APP'+'__/tags/index/['+'list:tag'+']" >['+'list:tag'+']</a> \n';
	outhtml+="<!--/"+mark+"-->";
	
	$('#echo').attr("value",outhtml);

};

function out_navlabel() {	
	
	var outhtml="<!"+"--vo:nav-->\n";
	outhtml+='<a href="[vo'+':curl]" >[vo'+':name]</a> >> \n';
    outhtml+="<!"+"--/nav-->\n";
	
	$('#echo').attr("value",outhtml);

};

function ins_html(content) {
	var mark=$('#mark').val(); //循环标识
	$('#echo').insertContent('['+mark+':'+content+']'); 
	}

function getfields(teble) {
   $.ajax({
     type: "POST",
     url: "__URL__/getfields",
	 data: {
			table: teble
		},
	dateType:"html",
	success: function(data) {
		$("#label_list").html('');
		var list_html = '';
		var fieldlist = data.split(',');
		for(var i =0 ;i<fieldlist.length;i++){
			list_html += '<a href="javascript:void(0)"  onclick="ins_html(\''+fieldlist[i]+'\')">'+fieldlist[i]+'</a>';
			}
			
		$("#label_list").append(list_html);
		
		}
		});
	}

 </script>
</body></html>